home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr11
/
pdox693.zip
/
TI542.ASC
< prev
next >
Wrap
Text File
|
1992-09-14
|
5KB
|
199 lines
PRODUCT : Paradox NUMBER : 542
VERSION : All
OS : DOS
DATE : September 14, 1992 PAGE : 1/3
TITLE : Stack Space/PAL Allocation of Stacks
This is an explanation of why the error "Run out of stack space"
is displayed by Paradox.
Stack space problems are the result of scripts or procedures
calling each other. The Paradox stack is used to keep track of
the script (or procedure) active at any time and which scripts
have been played.
The stack works on the premise that the last item placed on the
stack must be cleared before accessing any other item, sometimes
referred to as LIFO (Last In, First Out). This means that each
new procedure you call is placed on the stack, pushing down the
previous procedure. In order to develop an understanding of the
discussion, let's work with some examples.
If script FIRST calls script SECOND, the stack would look like
this:
FIRST
SECOND
Then, SECOND calls script FIRST again and now the stack becomes:
FIRST
SECOND
FIRST
This can continue until all the stack space is used up. The way
to prevent this recursive system from filling up all the stack
space, is to use the RETURN command. Using RETURN on the stack
problem yields the following allocation of stack space:
FIRST
SECOND
If script SECOND uses RETURN, instead of issuing PLAY FIRST,
SECOND will be "popped off" the stack, and control returns to
script FIRST. Now the stack looks like this:
FIRST
All of this information holds true whether you are using scripts
or procedures. The use of the WHERE? (press [Ctrl-W]) command is
PRODUCT : Paradox NUMBER : 542
VERSION : All
OS : DOS
DATE : September 14, 1992 PAGE : 2/3
TITLE : Stack Space/PAL Allocation of Stacks
very useful in locating where recursion happens. Chapter 10 of
the Paradox 4.0 PAL Reference Guide explains the usage of WHERE?.
The following pages contain scripts demonstrating the incorrect
method and correct method for stack usage.
release vars all
;This script demonstrates a STACK OVERFLOW error.
;
;--------------What NOT to DO-----------------
Proc main() ;Proc starts
Showmenu ;a menu
"Recursive" : "play this several times (15 or 20 to get debug)",
"Quit" : "Quit"
to z ;to a variable
Switch
case z = "Recursive": ;if they select this choice
jcdowrong() ;call jcdowrong procedure
case z = "Quit":
message "Adios" ;if they select quit
sleep 1000 ;give a message
Endswitch
EndProc
Proc jcdowrong() ;the bad procedure
if not isassigned(z1)
then z1 = 1
endif
Message "looped " + strval(z1)+ " times"
z1=z1+1
sleep 1000
main() ;this is the offending line
EndProc
Main() ;the actual script
PRODUCT : Paradox NUMBER : 542
VERSION : All
OS : DOS
DATE : September 14, 1992 PAGE : 3/3
TITLE : Stack Space/PAL Allocation of Stacks
; Rather than call the original procedure, let the procedure
; return naturally or use a "return" command
;----------------What to DO------------------
Proc goodmain() ;Proc starts
While(true) ;use the loop to eliminate
having to
;to recursive calls
Showmenu ;a menu
"NON-Recursive" : "play this several times(15 or 20 to get debug)",
;the choices
"Quit" : "Quit"
to z ;to a variable
Switch
case z = "NON-Recursive": ;if they select this choice
jcdoright() ;call jcdoright procedure
case z = "Quit":
message "Adios" ;if they select quit
sleep 1000 ;give a message
quitloop
Endswitch
endwhile
EndProc
Proc jcdoright()
if not isassigned(z2)
then z2 = 1
endif
Message "looped " + strval(z2)+ " times"
z2=z2+1
sleep 1000
EndProc
goodmain()
For additional information about PAL, refer to the PAL Reference
Guide (for versions earlier than 4.0, refer to the PAL User's
Guide).
DISCLAIMER: You have the right to use this technical information
subject to the terms of the No-Nonsense License Statement that
you received with the Borland product to which this information
pertains.